package com.zp.base.admin.service.impl;

import com.zp.base.admin.common.utils.PageUtils;
import com.zp.base.admin.common.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.zp.base.admin.dao.OperatorLogDao;
import com.zp.base.admin.entity.OperatorLogEntity;
import com.zp.base.admin.service.OperatorLogService;
import org.springframework.transaction.annotation.Transactional;


/**
 * @author zhangpeng
 * @email zhangpeng@aliyun.com
 * @date 2021-02-28 11:15:56
 */
@Service("operatorLogService")
@Transactional(rollbackFor = Exception.class)
public class OperatorLogServiceImpl extends ServiceImpl<OperatorLogDao, OperatorLogEntity> implements OperatorLogService {

    @Autowired
    OperatorLogDao operatorLogDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<OperatorLogEntity> page = this.page(
                new Query<OperatorLogEntity>().getPage(params),
                new QueryWrapper<OperatorLogEntity>().like("operator", params.get("operator"))
        );

        return new PageUtils(page);
    }

    @Override
    public List<OperatorLogEntity> getNewestOperatorLog(Integer i) {
        return operatorLogDao.getNewestOperatorLog(i);
    }

    @Override
    public int addOperatorLog(OperatorLogEntity operatorLogEntity) {
        operatorLogEntity.setCreateTime(new Date());
        operatorLogEntity.setUpdateTime(new Date());
        return operatorLogDao.insert(operatorLogEntity);
    }

    @Override
    public boolean deleteAll() {
        try {
            operatorLogDao.deleteAll();
            return true;
        } catch (Exception e) {
            log.error(e.getMessage());
            return false;
        }
    }


}